<template>
  <div class="user-wrapper">
    <div class="content-box" style="display:inline">
      <!-- <router-link :to="{ name: 'CompanyInfo' }">
        <span class="menubutton">
          <my-icon type="iconzu40"></my-icon>企业信息
        </span>
      </router-link> -->

      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <!-- <a-avatar class="avatar" size="small" :src="avatar" /> 注册暂未涉及男女等头像问题，目前采用默认头像，如下 -->
          <a-avatar
            size="small"
            style="backgroundColor:#87d068;margin-top:-4px;margin-right:2px"
            :src="imgAvater"
            v-if="avaterImg"
          />
          <a-avatar
            size="small"
            style="backgroundColor:#87d068;margin-top:-4px;margin-right:2px"
            icon="user"
            v-if="defaultImg"
          />
          <span style="margin-right:5px;margin-left:2px">{{ nickname2 }}</span>
          <a-icon type="down" />
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
          <!-- <a-menu-item key="0">
            <router-link :to="{ name: 'userCenter' }">
              <a-icon type="user" />
              <span>个人中心</span>
            </router-link>
          </a-menu-item> -->

          <a-menu-divider />
          <a-menu-item key="3">
            <a href="javascript:;" @click="handleLogout">
              <a-icon type="logout" />
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
 
  </div>
</template>

<script>

import NoticeIcon from '@/components/NoticeIcon'
import { mapActions, mapGetters } from 'vuex'
import Vue from 'vue'
import {
  ACCESS_TOKEN,
  ACCESS_TOKEN_Refresh,
  USER_ID,
  USER_NAME,
  COMPANY_ID,
  COMPANY_NAME,
  USER_AVATAR,
} from '@/store/mutation-types'
export default {
  name: 'UserMenu',
  components: {
    NoticeIcon,
  },
  computed: {
    ...mapGetters(['nickname', 'avatar']),
  },
  created() {
    this.nickname2 = Vue.ls.get('USER_NAME')
  },
  mounted() {
    setTimeout(() => {
      // this.nickname2 = Vue.ls.get('USER_NAME')
      this.nickname2 = '小明'
      let img = Vue.ls.get('USER_AVATAR')
      if (img != undefined) {
        if (img.length > 0) {
          this.imgAvater = img
          this.defaultImg = false
          this.avaterImg = true
        }
      }
    }, 500)
  },
  data() {
    return {
      // '何俊',
      defaultImg: true,
      avaterImg: false,
      imgAvater: '',
      nickname2: '',
      comName: '钢贸云信息技术有限公司',
    }
  },
  methods: {
    saveStockEvent(code,msg) {
     if(code == '200'){
        let type = 'success'
      this.$notification[type]({
        message: '温馨提示',
        description: '盘库成功！',
        duration: 2.5,
      })
     }
     if(code == '500'){
        let type = 'error'
      this.$notification[type]({
        message: '温馨提示',
        description: '盘库失败！',
        duration: 3,
      })
     }else{
       let type = 'error'
      this.$notification[type]({
        message: '温馨提示',
        description: msg,
        duration: 3,
      })
     }
     
    },
    ...mapActions(['Logout']),
    handleLogout() {
      this.$confirm({
        title: '提示',
        content: '确定要退出登陆?',
        onOk: () => {
          return this.Logout({})
            .then(() => {
              setTimeout(() => {
                //  console.log("退出登陆")
                  // window.location.reload()   
                  this.$router.replace({name: 'login'});
                
              }, 1000)
            })
            .catch((err) => {
              this.$message.error({
                title: '错误',
                description: err.message,
              })
            })
        },
        onCancel() {},
      })
    },
  },
}
</script>
<style scoped>
.menubutton {
  margin-right: 20px;
}
.comTitle {
  display: inline;
  margin-right: 250px;
  font-size: 23px;
  font-weight: 600;
}
</style>
